package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/10/17 09:05
 * @apiNote
 */

public class Test001640CanFormArray {

    public static void main(String[] args) {
        int[] arr = {49,18,16};
        int[][] prices = {{16,18,49}};
        boolean res = test(arr,prices);
        System.out.println(res);
    }


    public static boolean test(int[] arr, int[][] pieces) {
        int n = arr.length;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(arr[i], i);
        }
        int m = pieces.length;
        for (int i = 0; i < m; i++) {
            int[] price = pieces[i];
            int j = -1;
            if (map.containsKey(price[0])) {
                j = map.get(price[0]);
            } else {
                return false;
            }
            for (int num : price) {
                if (j >= n || arr[j] != num) {
                    return false;
                }
                j++;
            }
        }
        return true;
    }


}
